4af462
@@ -20,6 +20,7 @@
 
 import java.io.PrintStream;
 import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Map;
 
 import org.slf4j.Logger;
@@ -30,6 +31,7 @@
 import org.apache.hadoop.hive.conf.VariableSubstitution;
 import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.metastore.api.Schema;
+import org.apache.hadoop.hive.ql.CommandNeedRetryException;
 import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
@@ -74,7 +76,7 @@
public CommandProcessorResponse run(String command) {
         }
       }).substitute(ss.getConf(), command);
 
-      String[] tokens = command.split("\\s+");
+      String[] tokens = splitCmd(command);
       CommandProcessorResponse authErrResp =
           CommandUtil.authorizeCommand(ss, HiveOperationType.DFS, Arrays.asList(tokens));
       if(authErrResp != null){
@@ -104,4 +106,60 @@
public CommandProcessorResponse run(String command) {
     }
   }
 
+  private String[] splitCmd(String command) throws CommandNeedRetryException {
+
+    ArrayList<String> paras = new ArrayList<String>();
+    int cmdLng = command.length();
+    char y = 0;
+    int start = 0;
+
+    for (int i = 0; i < cmdLng; i++) {
+      char x = command.charAt(i);
+
+      switch(x) {
+        case ' ':
+          if ((int) y == 0) {
+            String str = command.substring(start, i).trim();
+            if (!str.equals("")) {
+              paras.add(str);
+              start = i + 1;
+            }
+          }
+          break;
+        case '"':
+          if ((int) y == 0) {
+            y = x;
+            start = i + 1;
+          } else if ('"' == y) {
+            paras.add(command.substring(start, i).trim());
+            y = 0;
+            start = i + 1;
+          }
+          break;
+        case '\'':
+          if ((int) y == 0) {
+            y = x;
+            start = i + 1;
+          } else if ('\'' == y) {
+            paras.add(command.substring(start, i).trim());
+            y = 0;
+            start = i + 1;
+          }
+          break;
+        default:
+          if (i == cmdLng-1 && start < cmdLng) {
+            paras.add(command.substring(start, cmdLng).trim());
+          }
+          break;
+      }
+    }
+
+    if ((int) y != 0) {
+      console.printError("Syntax error on hadoop options: dfs " + command);
+      throw new CommandNeedRetryException();
+    }
+
+    return paras.toArray(new String[paras.size()]);
+  }
+
 }
